package com.kly.cashmall.module.home.presenter;

import com.kly.cashmall.bean.UpdateBean;
import com.kly.cashmall.framework.mvp.BaseViewPresenter;
import com.kly.cashmall.module.home.home_tab.tab_view.HomeMainMenuAction;
import com.kly.cashmall.services.Network;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public class HomePagePresenter extends BaseViewPresenter<HomePageViewer> {

    public HomePagePresenter(HomePageViewer viewer) {
        super(viewer);
    }

    @Override
    public void willDestroy() {

    }


    public void preLoad() {
        rxManager.add(Network.getApi().getMenuList().subscribeOn(Schedulers.io()).observeOn
                (AndroidSchedulers.mainThread()).subscribe(new Consumer<List<HomeMainMenuAction>>() {
            @Override
            public void accept(List<HomeMainMenuAction> menuActionList) throws Exception {
                if (getViewer() != null) {
                    getViewer().onGetMenuListSuccess(menuActionList);
                }
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {

            }
        }));
    }
    public void getAppCode() {
        rxManager.add(Network.getApi().getConfigAppCode().subscribeOn(Schedulers.io()).observeOn
                (AndroidSchedulers.mainThread()).subscribe(new Consumer<UpdateBean>() {
            @Override
            public void accept(UpdateBean bean) throws Exception {
                if (getViewer() != null) {
                    getViewer().getAppCodeSuccess(bean);
                }
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                if (getViewer() != null) {
                    getViewer().getAppCodeFailed();
                }
            }
        }));
    }
}